<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CI留言板</title>
<script language="JavaScript" src="/statics/jquery.js">
</script>

<script type="text/javascript">
function re_load(tb){	
	$("#row"+tb).load("re_page?messageid="+tb);	
}
function loadface(face){
	if(face==1){
	$("#face").load("/message/face1");
	}else{
		$("#face").load("/message/face2");
		}
}
</script>

<script type="text/javascript">
$(document).ready(function(){
	var types={Btype1:[],Btype2:[]};
	var type1_value='<input type="checkbox" id="type1" value="PHP"/>\
		<a id=t1>PHP</a>\
		<br />\
		<input type="checkbox" id="type2" value="C语言" />\
		<a id=t2>C语言</a>\
		<br />\
		<input type="checkbox" id="type3" value="JAVA" />\
		<a id=t3>JAVA</a>\
		<br />';
	var type2_value='<input type="checkbox" id="type1" value="MYSQL"  />\
		<a id=t1>MYSQL</a>\
		<br />\
		<input type="checkbox" id="type2" value="SQL SERVER" />\
		<a id=t2>SQL SERVER</a>\
		<br />\
		<input type="checkbox" id="type3" value="ORACLE" />\
		<a id=t3>ORACLE</a>\
		<br />';
		function all(){
			i=types.Btype1.length+types.Btype2.length;
			return i;
			};
			function find(obj,value){
				for(i=0;i<types.Btype1.length;i++){
						if(types.Btype1[i].name==value) return true;
					}
				for(i=0;i<types.Btype2.length;i++){
					if(types.Btype2[i].name==value) return true;
				}
			return false;
			};
			function del(obj,value){
				for(i=0;i<types.Btype1.length;i++){
					if(types.Btype1[i].name==value) types.Btype1.splice(i,1) ;
				}
			for(i=0;i<types.Btype2.length;i++){
				if(types.Btype2[i].name==value) types.Btype2.splice(i,1);
			}
				}

			$('#Btype1').click(function(){
				if(($(this).val())=="on"){
					$('#typesvalue').html(type1_value);
					if(types.Btype1.length>0){
						if(find(types,'PHP')){
							$('#type1').attr('checked',true);	
							}
						if(find(types,'C语言')){
							$('#type2').attr('checked',true);	
							}
						if(find(types,'JAVA')){
							$('#type3').attr('checked',true);	
							}
						}
					}
			});

			$('#Btype2').click(function(){
				if(($(this).val())=="on"){
					$('#typesvalue').html(type2_value);
					if(types.Btype2.length>0){
						if(find(types,'MYSQL')){
							$('#type1').attr('checked',true);	
							}
						if(find(types,'SQL SERVER')){
							$('#type2').attr('checked',true);	
							}
						if(find(types,'ORACLE')){
							$('#type3').attr('checked',true);	
							}
						}
					}
			});

			$('#type1').live('click',function(){
				if((($('input:checkbox[id=type1]:checked').val())!=null)&&(!find(types,$(this).val()))&&(all()<3)){
				if(($('input:radio[id=Btype1]:checked').val())!=null){
					types.Btype1.push({name:$(this).val()});					
					}else if(($('input:radio[id=Btype2]:checked').val())!=null){
					types.Btype2.push({name:$(this).val()});	
					}
			}else if(($('input:checkbox[id=type1]:checked').val())==null){
				del(types,$(this).val());
			}else if(all()==3){$(this).attr('checked',false);alert('最多只能选择3个项！')}
				
			});

			$('#type2').live('click',function(){
				if((($('input:checkbox[id=type2]:checked').val())!=null)&&(!find(types,$(this).val()))&&(all()<3)){
				if(($('input:radio[id=Btype1]:checked').val())!=null){
					types.Btype1.push({name:$(this).val()});					
					}else if(($('input:radio[id=Btype2]:checked').val())!=null){
					types.Btype2.push({name:$(this).val()});	
					}
			}else if(($('input:checkbox[id=type2]:checked').val())==null){
				del(types,$(this).val());
			}else if(all()==3){$(this).attr('checked',false);alert('最多只能选择3个项！')}
				
			});

			$('#type3').live('click',function(){
				if((($('input:checkbox[id=type3]:checked').val())!=null)&&(!find(types,$(this).val()))&&(all()<3)){
				if(($('input:radio[id=Btype1]:checked').val())!=null){
					types.Btype1.push({name:$(this).val()});					
					}else if(($('input:radio[id=Btype2]:checked').val())!=null){
					types.Btype2.push({name:$(this).val()});	
					}
			}else if(($('input:checkbox[id=type3]:checked').val())==null){
				del(types,$(this).val());
			}else if(all()==3){$(this).attr('checked',false);alert('最多只能选择3个项！')}
				
			});

			/*$('#test').click(function(){
				console.log(types);
				});*/
			function posttype(){
				$.post("msg_insert",{types:JSON.stringify(types)},function(data){})	
				}

			/*$('#submit').click(function(){
				$.post("msg_insert", {types:JSON.stringify(types),readauth:$("#readauth").val(),title:$("#title").val(),user:$("#user").val(),msg:$("#msgid").val()},function(data){
				   });
				});*/

				$('#submit').click(function(){
					$("#posttype").val(JSON.stringify(types));
					});
})



</script>

</head>
<body>
<input type="button" name="reg" value="注册"
	onclick="window.location='reg'" />
&nbsp;&nbsp;&nbsp;
<input type="button" name="login" value="登录"
	onclick="window.location='login'" />
&nbsp;&nbsp;&nbsp;
<input type="button" name="logout" value="注销"
	onclick="window.location='logout'" />
<br />
<?php
//var_dump($_COOKIE);
setcookie('tmpuser',@$nowuser,time()-1);
if(isset($_COOKIE['username'])){
	$nowuser=$_COOKIE['username'];
	echo '用户名: '.$nowuser.'  ';
	if($_COOKIE['auth']=='1'){
		echo '权限: 游客';
	}elseif($_COOKIE['auth']=='2'){
		echo '权限: 普通会员';
	}elseif($_COOKIE['auth']=='3'){
		echo '权限: 管理员';
	}
}else{
	$nowuser='匿名用户';
	setcookie('auth','1',time()+60*60*12);
	echo '用户名: '.$nowuser.'  ';
	echo '权限: 游客';
}
setcookie('tmpuser',$nowuser,time()+60*60*12);

?>
<br />
<table width="900" border="0" align="center" cellpadding="5"
	cellspacing="2" bgcolor="#add3ef">
	<?php foreach ($msg as $row){
		$types=json_decode($row->type);
		$typestr='';
		for($i=0;$i<count($types->Btype1);$i++){
			$typestr=$typestr.$types->Btype1[$i]->name.' ';
		}
		for($i=0;$i<count($types->Btype2);$i++){
			$typestr=$typestr.$types->Btype2[$i]->name.' ';
		}
		?>
	<tr>
		<td>标题：<font color="red"><?=$row->title ?></font><br />
		用户名：<font color="red"><?=$row->username ?></font>
		<div align="right"><a
			href="Edit?id=<?=$row->messageid?>&count=<?=$_GET['count']?>">编辑</a>
		| <a
			href="msg_delete?id=<?=$row->messageid?>&count=<?=$_GET['count']?>">删除</a>
		| <a
			href="re_message?id=<?=$row->messageid?>&count=<?=$_GET['count']?>&user=<?=$nowuser ?>">回复</a></div>
		<br/>
		<font color="blue">留言类型：<?=$typestr ?></font>
		</td>
	</tr>
	<?php

	$tmpmessage1=array("/(\[#qqface:){1}/","/\]{1}/","/(\[#bbsface:){1}/");
	$tmpmessage2=array("<img src=\"/statics/face1/F_",".gif\"/>","<img src=\"/statics/face2/");
	$tmpmessage=preg_replace($tmpmessage1, $tmpmessage2,$row->message );
	?>
	<tr bgColor="#ffffff">
		<td valign="top" align="left">内容： <?php 
		if($row->readauth == '3'){
			if($_COOKIE['auth']=='3'){
				echo $tmpmessage;
			}else{
				echo '管理员可查看该留言！';
			}
		}elseif ($row->readauth == '2'){
			if(($_COOKIE['auth']=='3')||($_COOKIE['auth']=='2')){
				echo $tmpmessage;
			}else{
				echo '管理员或会员可查看该留言！';
			}
		}else{
			echo $tmpmessage;
		}
		?><br />
		</td>
		<td>
		<div id="row<?php echo $row->messageid; ?>"></div>
		<script type="text/javascript">
		<?php 
			echo 're_load('.$row->messageid.');';
		?>
	</script></td>
	</tr>
	<tr bgColor="#ffffff">
		<td>
		&nbsp;
		<div align="left"><?=$row->messageid ?>楼</div>
		<div align="right">发表日期：<?= $row->time?></div>
		</td>
	</tr>
	<?php }?>
</table>
<h3 align="center"><?php foreach ($pages as $fr){?> <a
	href="?count=<?=($fr-1)*5?>"><<?=$fr?>></a> <?php 
	if($fr % 7 ==0 ){
		echo '<br/>';
	}}?></h3>
<form method="post" action="msg_insert?count=<?=$_GET['count'] ?>"><br />
<input type="radio" name="typecheck" id="Btype1" /> 语言类型 <input
	type="radio" name="typecheck" id="Btype2" /> 数据库类型<br />
<p id="typesvalue"></p>

<p>标 题 : <input type="text" name="title" id="title" size="50"
	maxlength="50" /></p>
<p>用户名: <input type="text" name="user" id="user" value="<?=$nowuser ?>"
	readOnly size="20" maxlength="20" /></p>
<p>留言内容:</p>
<p><textarea name="msg" id="msgid" cols="80" rows="10" wrap="physical"></textarea></p>
<div id="face"></div>
<input type="button" value="QQ表情" onClick="loadface(1)" /> <input
	type="button" value="BBS表情" onClick="loadface(2)" />
<p><select name="readauth" id="readauth">
	<option>最高阅读权限</option>
	<option>普通阅读权限</option>
	<option >最低阅读权限</option>
</select></p>
<input type="hidden" name="types" id="posttype" value="" /> <input
	type="button" value="TEST" id="test" /><br />
<input type="submit" value="提交" id="submit" /></form>

</body>